$(function(){
	
	// 加载商品一级目录
	var i;
	$(".allOneCategory").text();
	$.ajax({
		url:"oneCategory_getAllOneCategory.action",
		type:"get",
		dataType:"json",
		success:function(data){
			// var data1 =$.parseJSON(data);
			for(i=0;i<data.data.length;i++){
				$("#oneCategory" + i).text(data.data[i].name);
				$("#categoryList" + i).attr("oneCategoryId", data.data[i].id);
			}
		}
	});
	
	// 商品一级分类鼠标悬停，获取该一级分类的所有二级和三级分类
	$(".categoryList").mouseenter(function(){
		$(".sub-cate-wrap").remove();
		var oneCategoryId = $(this).attr("oneCategoryId");
		var cateDetailId = oneCategoryId - 1;
		//alert(oneCategoryId);
		$.ajax({
			url:"twoCategory_getTwoThreeCategory.action",
			type:"get",
			dataType:"json",
			data:{oneCategoryId:oneCategoryId},
			success:function(data){
				//var result =$.parseJSON(data);
				var i;
				var j;
				// 遍历二级、三级分类大集合
				for(i=0;i<data.data.length;i++){
					$OneCate = $("#categoryDetail" + cateDetailId);
					$OneCate.append("<div class='sub-cate-wrap' id='sub-cate-wrap"+ i +"'></div>");
					$SubCateWrap = $("#sub-cate-wrap" + i);
					$SubCateWrap.append("<dl class='sub-category' id='sub-category"+ i +"'></dl>");
					$SubCategory = $("#sub-category" + i);
					// 二级分类名
					$SubCategory.append("<dt><a href='#'>"+ data.data[i].twoName +"</a></dt>");
					$SubCategory.append("<dd><ul class='three-category' id='three-category"+ i +"'></ul></dd>");
					$ThreeCategory = $("#three-category" + i);
					// 遍历二级、三级分类中的三级分类集合
					for(j=0;j<data.data[i].listThreeCategory.length;j++){
						$ThreeCategory.append("<li><a href='#'>"+ data.data[i].listThreeCategory[j].name +"</a></li>");
					}
				}
			}
	    });
	});	
	
	// 商品一级分类鼠标离开
	$(".categoryDetail").mouseleave(function(){
		$(".sub-cate-wrap").remove();
	});
	
	// 猜你喜欢的鼠标悬停事件
	$(".favorite ul li").on("click",function(){
		var index=$(this).index();
		if(index==0){
			$(".favoriteDetail .like").show();
			$(".favoriteDetail .newThings").hide();
			$(".favoriteDetail .sameSchool").hide();
		}else if(index==1){
			$(".favoriteDetail .like").hide();
			$(".favoriteDetail .newThings").show();
			$(".favoriteDetail .sameSchool").hide();
		}else{
			$(".favoriteDetail .like").hide();
			$(".favoriteDetail .newThings").hide();
			$(".favoriteDetail .sameSchool").show();
		}
		//$(".favoriteDetail div").eq(index).show().siblings().hide();
		$(this).attr('class',"lihover").siblings('li').attr('class','');
	});
	
	// 回到顶部
	$(".toTop").on("click",function(event){
		$("html,body").animate({scrollTop:0},500);
	});
	
	// 大轮播图
	var myswiper = new Swiper(".picRoll .swiper-container",{
		loop:true,
		autoplay:4000,
		effect : 'cube',
		autoplayDisableOnInteraction:false,
		pagination: '.swiper-pagination',
		nextButton: '.swiper-button-next',
	    prevButton: '.swiper-button-prev',
	});
	$(".picRoll .swiper-container").on("mouseover",function(){
		$(".picRoll .swiper-container .swiper-button-next").css("display","block");
		$(".picRoll .swiper-container .swiper-button-prev").css("display","block");
	}).on("mouseout",function(){
		$(".picRoll .swiper-container .swiper-button-next").css("display","none");
		$(".picRoll .swiper-container .swiper-button-prev").css("display","none");
		});
	
	// 小轮播图
	var myswiper1 = new Swiper(".sell-list .swiper-container",{
		/*direction: 'vertical',*/
		effect : 'flip',
		loop:true,
		autoplay:6000,
		autoplayDisableOnInteraction:true,
	});
	$(".on-selling .sell-list .item-list .item").on("mouseover",function(){
		$(".on-selling .sell-list .item-list .item .love").css("display","block");
		$(".on-selling .sell-list .item-list .item .love").css("display","block");
	}).on("mouseout",function(){
		$(".on-selling .sell-list .item-list .item .love").css("display","none");
		$(".on-selling .sell-list .item-list .item .love").css("display","none");
		});
	
});